package web.suzy.oj.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.entity.discussion.Discussion;
import web.suzy.oj.pojo.entity.discussion.DiscussionReport;
import web.suzy.oj.pojo.vo.DiscussionReportVO;
import web.suzy.oj.service.admin.discussion.AdminDiscussionService;

import java.util.List;

/**
 * YangSuzy 软件工作室
 * 类名: AdminDiscussionController
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/29 13:28
 */
@RestController
@RequestMapping("/api/admin")
public class AdminDiscussionController {
    @Autowired
    private AdminDiscussionService adminDiscussionService;

    /**
     * 方法名: removeDiscussion
     * 描述: 删除讨论
     *
     * @param didList 讨论ID列表
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/29 13:28
     * @auther YangSuzy
     **/
    @DeleteMapping("/discussion")
    @RequiresRoles(value = {"root", "admin", "problem_admin"}, logical = Logical.OR)
    @RequiresAuthentication
    public ResultBean<Void> removeDiscussion(@RequestBody List<Integer> didList) {
        return adminDiscussionService.removeDiscussion(didList);
    }

    /**
     * 方法名: updateDiscussion
     * 描述: 更新讨论
     *
     * @param discussion 讨论
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/29 13:56
     * @auther YangSuzy
     **/
    @PutMapping("/discussion")
    @RequiresRoles(value = {"root", "admin", "problem_admin"}, logical = Logical.OR)
    @RequiresAuthentication
    public ResultBean<Void> updateDiscussion(@RequestBody Discussion discussion) {
        return adminDiscussionService.updateDiscussion(discussion);
    }

    /**
     * 方法名: getDiscussionReport
     * 描述: 获取讨论举报信息
     *
     * @param limit       每页显示数目
     * @param currentPage 当前页
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < web.suzy.oj.pojo.vo.DiscussionReportVO>>
     * @date 2022/11/29 13:51
     * @auther YangSuzy
     **/
    @GetMapping("/discussion-report")
    @RequiresRoles(value = {"root", "admin", "problem_admin"}, logical = Logical.OR)
    @RequiresAuthentication
    public ResultBean<IPage<DiscussionReportVO>> getDiscussionReport(
            @RequestParam(value = "limit", defaultValue = "10") Integer limit,
            @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage) {
        return adminDiscussionService.getDiscussionReport(limit, currentPage);
    }

    /**
     * 方法名: updateDiscussionReport
     * 描述: 更新讨论举报信息
     *
     * @param discussionReport 举报信息
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/29 14:01
     * @auther YangSuzy
     **/
    @PutMapping("/discussion-report")
    @RequiresRoles(value = {"root", "admin", "problem_admin"}, logical = Logical.OR)
    @RequiresAuthentication
    public ResultBean<Void> updateDiscussionReport(@RequestBody DiscussionReport discussionReport) {
        return adminDiscussionService.updateDiscussionReport(discussionReport);
    }
}
